package com.cq.androidtools.notification

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Build
import androidx.core.app.NotificationCompat
import com.cq.androidtools.R
import com.cq.androidtools.databinding.AcNotificationBinding
import com.cq.base.activity.BaseViewBindingActivity

/**
 * 作者: CQ
 * 日期: 2022-07-07
 * 说明:
 */
class NotificationActivity2 : BaseViewBindingActivity<AcNotificationBinding>() {
    override fun initData() {
        super.initData()
        mBinding.text.text = "jjjjjjjjjjjjjjjjjjj"
    }

    private fun createNotificationForNormal() {
                val CHANNEL_ID = "channel_id"
                val CHANNEL_NAME = "channel_name"
                val NOTIFY_ID = 1
        val mManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW).apply {
                description = "miaoshu"
                setShowBadge(false) // 是否在桌面显示角标
            }

            mManager.createNotificationChannel(channel)

        }
        val intent = Intent(this, NotificationActivity2::class.java)
        val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
        val mBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_launcher_background)
            .setContentTitle("title")
            .setContentText("text")
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
            .setContentIntent(pendingIntent)
            .setAutoCancel(true)
        mManager.notify(NOTIFY_ID, mBuilder.build())

    }

}